﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace zijian666.AnyExtensions.Privates;

/// <summary>
/// 缓存常用的函数信息
/// </summary>
internal class Methods
{
    public static MethodInfo Enumerable_Contains { get; } = ((Func<IEnumerable<object>, object, bool>)Enumerable.Contains).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_Contains { get; } = ((Func<IQueryable<object>, object, bool>)Queryable.Contains).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_OrderByDescending { get; } = ((Func<IQueryable<object>, Expression<Func<object, object>>, IOrderedQueryable<object>>)Queryable.OrderByDescending).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_OrderBy { get; } = ((Func<IQueryable<object>, Expression<Func<object, object>>, IOrderedQueryable<object>>)Queryable.OrderBy).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_ThenByDescending { get; } = ((Func<IOrderedQueryable<object>, Expression<Func<object, object>>, IOrderedQueryable<object>>)Queryable.ThenByDescending).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_ThenBy { get; } = ((Func<IOrderedQueryable<object>, Expression<Func<object, object>>, IOrderedQueryable<object>>)Queryable.ThenBy).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_Where { get; } = ((Func<IQueryable<object>, Expression<Func<object, bool>>, IQueryable<object>>)Queryable.Where).Method.GetGenericMethodDefinition();
    public static MethodInfo Queryable_Any { get; } = ((Func<IQueryable<object>, Expression<Func<object, bool>>, bool>)Queryable.Any).Method.GetGenericMethodDefinition();

    public static MethodInfo String_Contains { get; } = ((Func<string, bool>)"".Contains).Method;
    public static MethodInfo String_StartsWith { get; } = ((Func<string, bool>)"".StartsWith).Method;
    public static MethodInfo String_EndsWith { get; } = ((Func<string, bool>)"".EndsWith).Method;

    internal static MethodInfo NullableParse_Build { get; } = ((Func<TryParseHandler<int?>?>)StringParserBuilder.BuildNullable<int>).Method.GetGenericMethodDefinition();
}